package com.hnevc.vx;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


import com.hnevc.vx.util.DB;

public class SignInActivity extends AppCompatActivity {
    private EditText signInusernameEt;
    private EditText signInstudentEt;
    private Button signInBtn;
    private String usernameStr;
    private String studentidStr;
    private EditText edtReput;
    private Button fahui;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);
        initView();
        initEvent();
    }

    private void initView() {
        signInusernameEt = (EditText) findViewById(R.id.sign_in_username_et);
        signInstudentEt = (EditText) findViewById(R.id.sign_in_student_id_et);
        edtReput = (EditText) findViewById(R.id.sign_in_student2_id_et);
        signInBtn = (Button) findViewById(R.id.sign_in_btn);
        fahui = (Button) findViewById(R.id.sign_in_return_btn);

    }

    private void initData() {
        usernameStr = signInusernameEt.getText().toString() + "";
        studentidStr = signInstudentEt.getText().toString() + "";

    }

    private void initEvent() {
        fahui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SignInActivity.this,LoginActivity.class);
                startActivity(intent);            }
        });
        signInBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initData();
                if (signInusernameEt.getText().toString().length() == 11) {
                    if (signInstudentEt.getText().toString().length() > 5 && signInstudentEt.getText().toString().length()<=15) {
                        if (edtReput.getText().toString().length() == signInstudentEt.getText().toString().length()) {
                            Toast.makeText(SignInActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(SignInActivity.this, LoginActivity.class);
                            startActivity(intent);
                        } else {
                            Toast.makeText(SignInActivity.this, "两次密码不一样", Toast.LENGTH_SHORT).show();
                        }
                    }
                    else {
                        Toast.makeText(SignInActivity.this, "密码格式不符合要求", Toast.LENGTH_SHORT).show();
                    }
                }
                else {
                    Toast.makeText(SignInActivity.this, "手机号码不符合要求", Toast.LENGTH_SHORT).show();
                }
                DB db = new DB(SignInActivity.this);
                db.signInInsert(usernameStr, studentidStr);

            }
        });
    }

}
